/*
 * @Description: 本地存储
 *  
 * @Date: 2021-03-31 09:27:19
 */
/**
 * 数据使用localstore存储
 * 存储本地缓存需要数据
 */
export const ls = {
	//本地存数据，days 有效时间（天）
	setItem: function(key, value, days) {
		let Days = days || 1000 //有效时间默认1000天
		let exp = new Date()
		let expires = exp.getTime() + Days * 24 * 60 * 60 * 1000

		localStorage.setItem(
			key,
			JSON.stringify({
				value,
				expires,
			})
		)
	},
	getItem: function(key) {
		let o = JSON.parse(localStorage.getItem(key))

		if (o !== null && Date.now() < o.expires) {
			return o.value
		} else {
			return null
		}
	},
	removeItem: function(key) {
		localStorage.removeItem(key)
	},
}

export const localStore = {
	getUserInfo: () => {
		let v = ls.getItem('UserInfo')
		if (v) {
			v.username = v.username || v.userName
		}
		return v
	},
	setUserInfo: (v) => {
		if (v) {
			v.username = v.username || v.userName
		}
		return ls.setItem('UserInfo', v)
	},
	delUserInfo: () => {
		return ls.removeItem('UserInfo')
	},
	// 临时传递消息详情
	getMessageInfo: () => {
		return ls.getItem('MessageInfo')
	},
	setMessageInfo: (v) => {
		return ls.setItem('MessageInfo', v)
	},
	delMessageInfo: () => {
		return ls.removeItem('MessageInfo')
	},
	// 临时传递客屏详情
	getContentInfo: () => {
		return ls.getItem('ContentInfo')
	},
	setContentInfo: (v) => {
		return ls.setItem('ContentInfo', v)
	},
	delContentInfo: () => {
		return ls.removeItem('ContentInfo')
	},
	// 临时传递角色详情
	getRoleInfo: () => {
		return ls.getItem('RoleInfo')
	},
	setRoleInfo: (v) => {
		return ls.setItem('RoleInfo', v)
	},
	delRoleInfo: () => {
		return ls.removeItem('RoleInfo')
	},
	// 临时传递支付订单详情
	getEposOrderInfo: () => {
		return ls.getItem('EposOrder')
	},
	setEposOrderInfo: (v) => {
		return ls.setItem('EposOrder', v)
	},
	delEposOrderInfo: () => {
		return ls.removeItem('EposOrder')
	},
	// 临时传递客屏详情
	getStoreContentInfo: () => {
		return ls.getItem('StoreContentInfo')
	},
	setStoreContentInfo: (v) => {
		return ls.setItem('StoreContentInfo', v)
	},
	delStoreContentInfo: () => {
		return ls.removeItem('StoreContentInfo')
	},
	// 临时传递客屏详情
	getBlackInfo: () => {
		return ls.getItem('BlackInfo')
	},
	setBlackInfo: (v) => {
		return ls.setItem('BlackInfo', v)
	},
	delBlackInfo: () => {
		return ls.removeItem('BlackInfo')
	},
}

export default localStore
